class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		vector<int> count(256);
		int pre = 0;
		int n = s.length();

		int ans = 0;
		for (int i = 0; i < n; ++i) {
			++count[s[i]];
			while (count[s[i]] > 1) {
				--count[s[pre]];
				++pre;
			}
			if (i - pre + 1 > ans) {
				ans = i - pre + 1;
			}
		}
		return ans;

    }
};